<?php
// +----------------------------------------------------------------------
// | Description: 系统用户
// +----------------------------------------------------------------------
// | Author: linchuangbin <linchuangbin@honraytech.com>
// +----------------------------------------------------------------------

namespace app\admin\controller;



class Demand extends ApiCommon
{

    public function index()
    {
        $biddingModel = model('demand');
        $param = $this->param;
        $page = !empty($param['page']) ? $param['page'] : '';
        $limit = !empty($param['limit']) ? $param['limit'] : '';
        $data = $biddingModel->getDataList($page, $limit, $param);
        return resultArray(['data' => $data]);
    }

    public function save()
    {
        $Model = model('demand');
        $param = $this->param;
        $data = $Model->createData($param);
        if (!$data) {
            return resultArray(['error' => $userModel->getError()]);
        }
        return resultArray(['data' => '添加成功']);
    }

    public function update()
    {
        $Model = model('demand');
        $param = $this->param;
        $data = $Model->updateDataById($param, $param['id']);
        if (!$data) {
            return resultArray(['error' => $Model->getError()]);
        }
        return resultArray(['data' => '编辑成功']);
    }

    public function delete()
    {
        $userModel = model('demand');
        $param = $this->param;
        $data = $userModel->delDataById($param['id']);
        if (!$data) {
            return resultArray(['error' => $userModel->getError()]);
        }
        return resultArray(['data' => '删除成功']);
    }

    public function deletes()
    {
        $Model = model('demand');
        $param = $this->param;
        $data = $Model->delDatas($param['ids']);
        if (!$data) {
            return resultArray(['error' => $Model->getError()]);
        }
        return resultArray(['data' => '删除成功']);
    }

    public function upload()
    {
        header('Access-Control-Allow-Origin: *');
        header('Access-Control-Allow-Methods: POST');
        header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept");
        $file = request()->file('file');
        if (!$file) {
            return resultArray(['error' => '请上传文件']);
        }
        $info = $file->validate(['ext' => 'xlsx']);
        if ($info) {
            $Model = model('demand');
            $param = $this->param;
            $data=$Model->multipleSave($file,$param['bid_id']);
            if (!$data) {
                return resultArray(['error' => $Model->getError()]);
            }
        }
        return resultArray(['data' => '添加成功']);
    }
    public function ext()
    {
        $Model = model('demand');
        $param = $this->param;
        $data=$Model->ext($param);
        if (!$data) {
            return resultArray(['error' => $Model->getError()]);
        }
        return resultArray(['data' => $data]);
    }
    public function updateExt(){
        $Model = model('demand');
        $param = $this->param;
        $res=$Model->updateExt($param);
        if (!$res) {
            return resultArray(['error' => $Model->getError()]);
        }
        return resultArray(['data' => '修改成功']);
    }
}
